import React from 'react';
import { Route } from 'react-router-dom';
import { getToken } from 'utils/storage';

export default function AutoRoute(props) {
  const { path, component: Com } = props;
  return (
    <Route
      path={path}
      render={(props) => {
        // console.log(props);
        // if (!!getToken())  !! 表示强制转换
        if (getToken()) {
          return <Com {...props}></Com>;
        }
        props.history.push('/login');
        // return <Login {...props}></Login>
      }}
    ></Route>
  );
}
